package com.example.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2023-01-12
 * Time: 16:41
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @RequestMapping("/login")
    public boolean login(HttpServletRequest request,String name,String password) {
        //1.非空判断
        if(StringUtils.hasLength(name)&&StringUtils.hasLength(password)) {
            //验证用户名和密码
            if("小卢".equals(name)&&"123".equals(password)) {
                //登录成功
                HttpSession session = request.getSession();
                session.setAttribute("userinfo","admin");
                return true;
            } else {
                //用户名和密码输入错误
                return false;
            }
        }
        return false;
    }
    @RequestMapping("/getinfo")
    public String getInfo() {
        log.debug("执行了getinfo方法");
        return "执行了getinfo方法";
    }
    @RequestMapping("/reg")
    public String reg() {
        log.debug("执行了reg方法");

        return "执行了reg方法";
    }
}
